
package at.fhj.ase.clientarch.server.control;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.fhj.ase.clientarch.common.util.CommonUtil;
import at.fhj.ase.clientarch.server.component.RMIController;
import at.fhj.ase.clientarch.server.db.dao.impl.DatabaseController;
import at.fhj.ase.clientarch.server.sigar.SigarController;

/**
 * @author cja, sfe | www.fh-joanneum.at | Client Architectures and Design
 */
public enum ServerController {
  /**
   * The sole instance of this {@link ServerController} which equals a singleton pattern implementation Furthermore this results in that this controller is
   * visible to the whole application.
   */
  INSTANCE;

  private final Logger logger = LoggerFactory.getLogger(getClass().getName());

  public void startApplication() throws Throwable {
    try {
      // init all controllers 
      RMIController.INSTANCE.init();
      DatabaseController.INSTANCE.init();

      SigarController.INSTANCE.init(); //database uses SigarController only at timer, therefore it must be started before
      DatabaseController.INSTANCE.startTimer();
    } catch (Throwable t) {
      logger.error("Troubles starting server application, quitting...", t);
      throw t;
    }

    logger.debug("Server up and running on port " + CommonUtil.RMI_PORT);
  }
}
